package com.tgy.helloworld.service;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.transaction.Transactional;

/***
 * @ClassName: TransactionalService
 * @Description:
 * @Auther: 送你一块二向箔
 * @Date: 15:41 2022/4/23
 * @version : V1.0
 */
@Service
public class TransactionalService {
    @Resource
    JdbcTemplate jdbcTemplate;

    @Transactional
    public void add() {
        jdbcTemplate.execute("insert into user(name) values('tgy')");
        //这个名字超长这里会报错，如果加了事务上面的sql就会回滚，如果没加上面的就会执行成功
        jdbcTemplate.execute("insert into user(name) values('tgy123456')");
        jdbcTemplate.execute("insert into user(name) values('tgy')");

    }

}
